package org.cttic.visualization.visualization.util.sixUtil;

import cn.hutool.json.JSONUtil;
import org.cttic.visualization.visualization.common.module.provinceData;
import org.cttic.visualization.visualization.common.module.stationCountData;
import org.cttic.visualization.visualization.common.module.stationCountData.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author shkstart
 * @create 2020-06-02 15:28
 */
@Component
public class stationCountUtil {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public long stationCountQueryUtil(String startTime,String endTime,String provincel,List<vehArr> list){
        vehArr vehArr = new vehArr();
        long total=0L;
        vehArr.quotaStation quotaStation = new vehArr.quotaStation();
        String querySql="SELECT sum(enCount) as enCount,sum(exCount) as exCount,sum(totalCount) as totalCount FROM `stationCount` WHERE provinceId= '"+ provincel + "'" +
                " and processingTime<'"+endTime+"' and processingTime>'"+startTime+"'";
        System.out.println(querySql);
        Map<String, Object> stationCountMap = jdbcTemplate.queryForMap(querySql);
        if(stationCountMap!=null&&stationCountMap.size()>0) {
            cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(stationCountMap);

            Long enCount = jsonObject.getLong("enCount");
            Long exCount = jsonObject.getLong("exCount");
            Long totalCount = jsonObject.getLong("totalCount");
            quotaStation.setEnCount(enCount + "");
            quotaStation.setExCount(exCount + "");
            quotaStation.setTotalCount(totalCount + "");
            vehArr.setProvinceId(provincel);
            vehArr.setProvinceName(provinceData.provinceID.get(Integer.parseInt(provincel)));
            vehArr.setQuotaInfo(quotaStation);

            total += totalCount;
            list.add(vehArr);
            return total;
        }
        return 0;
    }
}
